package com.sunda.spmswms.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sunda.spmswms.entity.Whs;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 仓库信息表 Mapper 接口
 * </p>
 *
 * @author Wayne
 * @since 2020-11-24
 */
@Mapper
@Component
public interface WhsMapper extends BaseMapper<Whs> {

    @Select("SELECT w.WERKS AS \"werks\",\n" +
            "w.WHS_LOCATION_CODE AS \"whsLocationCode\",\n" +
            "w.WHS_LOCATION_DESC AS \"whsLocationDesc\",\n" +
            "w.WHS_TYPE AS \"whsType\",\n" +
            "w.CONTACT AS \"userId\",\n" +
            "w.ADDRESS AS \"address\",\n" +
            "w.TELEPHONE AS \"telephone\",\n" +
            "w.CITY AS \"city\"\n" +
            " FROM WHS w WHERE w.WERKS = #{werks}")
    List<Map<String, Object>> getWhsByWerks(@Param("werks") String werks);

    @Select("SELECT WE.WERKS AS \"werks\",\n" +
            "       WE.WERKS_NAME_EN AS \"werksNameEn\",\n" +
            "       WE.WERKS_NAME_ZH AS \"werksNameZh\",\n" +
            "       WE.COMPANY_CODE AS \"companyCode\",\n" +
            "       WE.COMPANY_NAME_EN AS \"companyNameEn\",\n" +
            "       WE.COMPANY_NAME_ZH AS \"companyNameZh\",\n" +
            "       WE.REGIO_GROUP AS \"regioGroup\",\n" +
            "       WE.COUNTRY AS \"country\",\n" +
            "       WH.WHS_LOCATION_CODE AS \"whsLocationCode\",\n" +
            "       WH.WHS_LOCATION_DESC AS \"whsLocationDesc\",\n" +
            "       WH.WHS_TYPE AS \"whsType\",\n" +
            "       WH.ADDRESS AS \"address\",\n" +
            "       WH.CITY AS \"city\"\n" +
            "FROM WERKS WE LEFT JOIN WHS WH ON WE.WERKS = WH.WERKS " +
            "WHERE WH.WHS_LOCATION_CODE IS NOT NULL " +
            "ORDER BY WE.WERKS, WH.WHS_LOCATION_CODE ASC")
    List<Map<String, Object>> getAllWhs();
}
